package com.gwcloud.leetcode.offers;

/** 
* @ClassName   : Leetcode0570 
* @author      : ganwei 
* @date        : 2020年6月8日 
* @Description : TODO 
*/
public class Leetcode0570 {
    public int[] twoSum(int[] nums, int target) {
    	int start = 0, end = nums.length-1;
    	int[] res = new int[2];
    	while(start <= end) {
    		System.out.println("start: " + start);
    		System.out.println("end: " + end);
    		if(nums[start] + nums[end] == target) {
    			res[0] = start;
    			res[1] = end;
    			break;
    		}else if(nums[start] + nums[end] < target) {
    			start++;
    		}else {
    			end--;
    		}
    	}
    	return res;
    }
    /**
     * -主函数
     */
    public static void main(String[] args) {
    	Leetcode0570 l0570 = new Leetcode0570();
    	int[] nums = {2,7,11,15};
    	l0570.twoSum(nums, 9);
    }
}
